package pl.smath.web.client;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class InputExpressionWidget extends Composite {

	private DecoratorPanel decPanel = new DecoratorPanel();
	private HorizontalPanel mainPanel = new HorizontalPanel();
	private VerticalPanel vPanel = new VerticalPanel();
	private Button calculateButton = new Button();
	private TextBox expressionTextBox = new TextBox();
	private Label label = new Label();
	
	public InputExpressionWidget(){
		initWidget(decPanel);
		label.setText("Podaj wyrażenie:");
	    calculateButton.setText("Rozwiąż");
	    mainPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
	    mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
	    mainPanel.add(expressionTextBox);
	    mainPanel.add(calculateButton);

	    vPanel.add(label);
	    vPanel.add(mainPanel);
	    
	    decPanel.setWidget(vPanel);

	    vPanel.setStylePrimaryName("input_expression_widget_vPanel_panel");
	    calculateButton.setStylePrimaryName("input_expression_widget_calculate_button");
	    label.setStylePrimaryName("input_expression_widget_label");
	    expressionTextBox.setStylePrimaryName("input_expression_widget_expression_text_box");
	    expressionTextBox.setText("2*x+(x+1)*(3*x-1)");
	}
	
	public void setClickHandler(ClickHandler handler){
		calculateButton.addClickHandler(handler);
	}
	
	public String getExpression(){
		return expressionTextBox.getText();
	}
}
